package com.log4jviewer.domain;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import com.log4jviewer.logfile.LogRecord;
import com.log4jviewer.logfile.fields.LogLevelName;

public class FileLogEventTest {

    private LogRecord mock;
    private FileLogEvent fileLogEvent;

    @Before
    public void init() {
        mock = mock(LogRecord.class);
        fileLogEvent = new FileLogEvent(mock);
    }

    @Test
    public void logInfoTest() {
        when(mock.getCategoryName()).thenReturn("CategoryName");
        Assert.assertEquals("CategoryName", fileLogEvent.getCategoryName());

        when(mock.getClassName()).thenReturn("ClassName");
        Assert.assertEquals("ClassName", fileLogEvent.getClassName());

        when(mock.getDate()).thenReturn("Date");
        Assert.assertEquals("Date", fileLogEvent.getDate());

        when(mock.getFileName()).thenReturn("FileName");
        Assert.assertEquals("FileName", fileLogEvent.getFileName());

        when(mock.getLineNumber()).thenReturn(-7);
        Assert.assertEquals("", fileLogEvent.getLineNumber());

        when(mock.getLineNumber()).thenReturn(7);
        Assert.assertEquals("7", fileLogEvent.getLineNumber());

        when(mock.getMdc()).thenReturn("Mdc");
        Assert.assertEquals("Mdc", fileLogEvent.getMdc());

        when(mock.getMessage()).thenReturn("Message");
        Assert.assertEquals("Message", fileLogEvent.getMessage());

        when(mock.getMethodName()).thenReturn("MethodName");
        Assert.assertEquals("MethodName", fileLogEvent.getMethodName());

        when(mock.getNdc()).thenReturn("Ndc");
        Assert.assertEquals("Ndc", fileLogEvent.getNdc());

        when(mock.getLevel()).thenReturn(LogLevelName.DEBUG);
        Assert.assertEquals("DEBUG", fileLogEvent.getLevel());

        when(mock.getThreadName()).thenReturn("ThreadName");
        Assert.assertEquals("ThreadName", fileLogEvent.getThreadName());
    }

    @Test
    public void emptyLogInfoTest() {
        Assert.assertEquals("", fileLogEvent.getCategoryName());
        Assert.assertEquals("", fileLogEvent.getClassName());
        Assert.assertEquals("", fileLogEvent.getDate());
        Assert.assertEquals("", fileLogEvent.getFileName());
        Assert.assertEquals("", fileLogEvent.getLineNumber());
        Assert.assertEquals("", fileLogEvent.getMdc());
        Assert.assertEquals("", fileLogEvent.getMessage());
        Assert.assertEquals("", fileLogEvent.getMethodName());
        Assert.assertEquals("", fileLogEvent.getNdc());
        Assert.assertEquals("", fileLogEvent.getLevel());
        Assert.assertEquals("", fileLogEvent.getThreadName());
        Assert.assertEquals("", fileLogEvent.getThrowableInfo());
    }
}
